<?php
require 'include.php';
$error = "";
if($user_id = check_cookie()){
	$membre = new membre($user_id);
	redirect('accueil.php');
}
elseif(!empty($_POST['nom'])){
	$vars = array('nom','ddn');
	foreach($vars as $var){
		$$var = (!empty($_POST[$var])) ? $_POST[$var] : "";
	}
	if($nom == 'invite'){
		redirect('accueil.php');
	}
	else{
		$ddn3 = ereg_replace("[^0-9]","",$ddn);
		$ddn1 = substr($ddn3,4,4)."-".substr($ddn3,2,2)."-".substr($ddn3,0,2);
		$ddn2 = substr($ddn3,0,4)."-".substr($ddn3,4,2)."-".substr($ddn3,6,2);
		$q = "select id from membres where nom = '".(addslashes($nom))."' and (ddn = '$ddn2' or ddn = '$ddn1')";
		$r = ExecRequete($q);
		error_log($q);
		if($s = LigneSuivante($r)){
			$membre = new membre($s->id);
			$param = time() +  86400*365;
			$check = $s->id * strlen($membre->nom) + strlen($membre->prenom);
			$cookie = $s->id.":".$check;
			setcookie("VBCLL2",$cookie,$param);
			redirect('accueil.php');
		}
		else $error = "identification &eacute;chou&eacute;e";
	}
}
entete('Login');
echo "<h1>Identifiez-vous</h1>\n";
ob_start();
echo "<form action = 'index.php' method = 'post'>\n";
echo "<p><input type = 'text' name = 'nom' size = '20' value = 'nom de famille' style = 'color: #888;' onclick = 'if(this.value == \"nom de famille\") this.value = \"\"; this.style.color = \"#000\";' /></p>\n";
echo "<p><input type = 'text' name = 'ddn' size = '20' value = 'date de naissance' style = 'color: #888;' onclick = 'if(this.value == \"date de naissance\") this.value = \"\";this.style.color = \"#000\"' /></p>\n";
echo "<p><button type = 'submit' style = 'width:200px' >identifier</button></p>\n";
echo "</form>\n";
echo "<p><button type = 'button' style = 'width:200px'  onclick = 'self.location.href = \"accueil.php\"'>invit&eacute;</button></p>\n";
$content = ob_get_clean();
$title = ($error) ? "<span class = 'perdu center'>$error</span>" : "";
echo box($title,$content,250,1);
pied();












?>
